package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.invisible
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.models.DepartmentBean
import com.compass.mobile.models.Title
import getColorFromResource

/**
 * Description： 科室Presenter
 * Date:2024/5/21 20:17
 */
class DepartmentPresenter : Presenter() {
    private var finalWidth: Int? = null
    fun setFinalWidth(finalWidth: Int?) {
        this.finalWidth = finalWidth
    }

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_department, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is DepartmentBean) {
            val vh = viewHolder as ViewHolder
            vh.layoutParams.height = (finalWidth!! * 0.7).toInt()
            vh.itemView.layoutParams = vh.layoutParams
            vh.tvTitle.text = item.name
            vh.tvValue.text = item.cruxIntroduce

            if(item.hotStatus == 1){
                vh.ivIcon.visible()
//                vh.tvTitle.setTextColor(getColorFromResource(R.color.text_ff))
            }else{
                vh.ivIcon.gone()
//                vh.tvTitle.setTextColor(getColorFromResource(R.color.white))
            }
//            vh.itemView.onFocusChangeListener = View.OnFocusChangeListener{view,hasFocus->
//                if(hasFocus&&item.hotStatus == 1){
//                    vh.ivIcon.gone()
//                }else if(!hasFocus && item.hotStatus == 1){
//                    vh.ivIcon.visible()
//                }else{
//                    vh.ivIcon.gone()
//                }
//
//            }

        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {

    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView
        var tvValue: TextView
        var ivIcon:ImageView
        var itemView: LinearLayout
        var layoutParams: ViewGroup.LayoutParams

        init {
            tvTitle = view.findViewById(R.id.tv_title)
            tvValue = view.findViewById(R.id.tvValue)
            itemView = view.findViewById(R.id.itemView)
            ivIcon = view.findViewById(R.id.iv_star)
            layoutParams = itemView.layoutParams
        }
    }
}
